<template>
  <Dialog
    width="800px"
    :title="title"
    v-model="dialogTableVisible"
    @confirm="confirm"
    @cancel="cancel"
    clickBtn="show"
  >
    <template #content>
      <div class="content" v-if="strList">
        <span>日期/小时：</span>
        <span>{{ strList ? strList[0].substring(0, 10) : '' }}</span>
      </div>
      <el-table :data="list" @cell-click="showChart" style="width: 100%">
        <el-table-column prop="code" label="测点编号" width="180">
        </el-table-column>
        <el-table-column
          v-for="(item, index) in strList"
          :key="index"
          :label="item.slice(11)"
          :prop="item"
          :show-overflow-tooltip="true"
          :class-name="item.className"
          :sortable="item.sortable"
          ><span style="cursor: pointer">查看</span>
        </el-table-column>
      </el-table>
    </template>
  </Dialog>
</template>

<script>
import Dialog from '@/components/Dialog/index.vue'
import FormMixin from '@/mixins/FormMixin.js'
import { getAction, postFormAction3 } from '@/api/common'

export default {
  name: 'ChartDialog',
  props: [''],
  mixins: [FormMixin],
  data() {
    return {
      dialogTableVisible: false,
      list: [],
      strList: '',
      query: {}
    }
  },

  components: { Dialog },

  created() {},

  mounted() {},

  methods: {
    init(query, title) {
      this.query = query
      postFormAction3('/SensorDatas/chartIndex', query)
        .then((res) => {
          if (res.flag) {
            this.title = '生成图表【' + title + '】'
            this.strList = res.data.strList
            this.list = res.data.pagedList.list
            this.dialogTableVisible = true
          } else {
            this.$message.error(res.message)
          }
        })
        .catch((err) => this.$message.error('服务器错误，请稍后重试'))
    },
    showChart(row, column) {
      let query = {
        asyncID: this.query.asyncID,
        code: row.code,
        date: this.strList[0].substring(0, 10) + ' ' + column.label
      }
      getAction('/sensorDatas/table', query).then((res) => {
        if (res.flag) {
          this.$emit('showLineDialog', res.data)
        } else {
          this.$message.error(res.message)
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  font-weight: 700;
  margin-bottom: 10px;
}
</style>
